home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2351 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: newsfeed.pitt.edu!jbilla
  2. From: jbilla+@pitt.edu (Jayadev  Billa)
  3. Newsgroups: comp.lang.c
  4. Subject: Weird malloc() seg-faults [Need Help!]
  5. Date: 20 Jan 1996 19:57:36 GMT
  6. Organization: University of Pittsburgh
  7. Message-ID: <4drhfg$m9s@usenet.srv.cis.pitt.edu>
  8. Reply-To: jabst45+@pitt.edu
  9. NNTP-Posting-Host: scorpion.labs.cis.pitt.edu
  10. Keywords: malloc, weird, segmentation faults, bad programming?, help
  11.  
  12. Hi folks:
  13.  
  14. I have been having problems with seg-faults with malloc.
  15.  
  16. HW/SW: Pentium-90, 16MB, gcc-2.5.8 with libc-4.5.26.
  17.  
  18. Description/Setup: I have libraries that I have built up over the past 
  19. year and have had no problem, till now. Specifically the program 
  20. segfaults within malloc, gdb shows the problem as
  21.  
  22. (gdb) run  as1.out
  23. Starting program: /home/jbilla/HTK/dap/prog/testapf as1.out
  24. CF #   1        gnuplot testapf.gnu
  25.  
  26. Program received signal SIGSEGV, Segmentation fault.
  27. 0xcebc in malloc (size=128) at malloc.c:193
  28. malloc.c:193: No such file or directory.
  29. (gdb) where
  30. #0  0xcebc in malloc (size=128) at malloc.c:193
  31. #1  0xd8c6 in calloc (nmemb=32, size=4) at calloc.c:33
  32. #2  0x235e in CreateVector (size=31) at miscmath.c:28
  33. #3  0xa08d in toeplz (r=0x1af00, x=0x1bf00, y=0x1bc80) at nrmath.c:546
  34. #4  0x9f05 in stoeplz (r=0x1be00, x=0x1bf00, y=0x1bc80) at nrmath.c:529
  35. #5  0x5683 in FindDAPFilter (h=0x203000, a=0x1b000) at miscmath.c:911
  36. #6  0xb049 in main (argc=2, argv=0xbffff904) at testapf.c:102
  37.  
  38. CreateVector is a simple call to calloc as:
  39.  
  40. --
  41.  
  42. typedef float*  Vector;
  43.  
  44. Vector CreateVector(int size)
  45. {
  46.   Vector vec;
  47.  
  48.   if ((vec = (Vector) calloc(size+1,sizeof(float)))==NULL)
  49.     WError(10,"Unable to allocate memory for Vector");
  50.   *vec = (float) size;
  51.   return(vec);
  52. }
  53.  
  54. void FreeVector(Vector vec)
  55. {
  56.   free(vec);
  57. }
  58.  
  59. --
  60.  
  61. I can't figure out what the problem is. It is reproducible and the calls
  62. to the routines are valid as far as I can see, memory doesnt seem to be 
  63. a problem (should return NULL anyways for such a case). 
  64.  
  65. I'd apprieciate any help/tips/suggestions. Thanks,
  66.  
  67. Jay.
  68. jabst45+@pitt.edu
  69.  
  70.